<import file="block/common.html" name="url" :tpl_cfg="['urlName'=>'日志列表']"/>
<div class="layui-fluid">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter"></table>
			<script type="text/html" id="toolbarAE">
				<div class="layui-form">
					<div class="layui-inline layui-show-xs-block">
						<input type="text" name="username" id="tableReload" placeholder="搜索用户名查找对应日志" autocomplete="off" class="layui-input">
					</div>
					<div class="layui-inline layui-show-xs-block">
						<button class="layui-btn layui-btn-sm" data-type="reload" id="search"><i class="layui-icon">&#xe615;</i></button>
					</div>
						<?php if(LoginUserInfo('gid') == 1){echo "<button class='layui-btn layui-btn-sm data-clear-btn layui-btn-danger'><i class='layui-icon'>&#xe640;</i>清除所有日志</button>"; }?>
					<!---<h4>只保留5000条数据</h4>--->
				</div>
			</script>
			<script type="text/html" id="timeTpl">{{ layui.util.timeAgo(d.time)}}</script>
		</div>
	</div>
</div>
<script>
	layui.define(function () {
		var table = layui.table,
			$ = layui.jquery;
		table.render({
			elem: '#currentTableId',
			url: '<{CAUrl("log","index")}>&list_json',
			toolbar: '#toolbarAE',
			defaultToolbar: ['filter', 'exports', 'print', {
				title: '提示',
				layEvent: 'LAYTABLE_TIPS',
				icon: 'layui-icon-tips'
			}],
			page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
				layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局
				//,curr: 5 //设定初始在第 5 页
				, groups: 1 //只显示 1 个连续页码
				, first: false //不显示首页
				, last: false //不显示尾页
			},
			cols: [[
				//{type: "checkbox", width: 50, fixed: "left"},
				{ field: 'id', width: 80, title: 'ID', sort: true },
				{ field: 'username', width: 100, title: '用户' ,sort: true},
				{ field: 'nickname', width: 100, title: '昵称'},
				{ field: 'loginip',width: 150, title: 'IP' ,sort: true},
				{ field: 'ca',width: 190, title: '控制器及方法' ,sort: true},
				{ field: 'dothing', width: 380, title: '描述'},
				{ field: 'time', width: 120, title: '操作时间',sort: true , templet: '#timeTpl'},
				{ field: 'useragent',  title: '客户端信息'},
			]],
			limits: [10, 15, 20, 25, 50, 100],
			limit: 20,
			page: true,
			id: 'tableReload',
		});

		//搜索重载表格
		var $ = layui.$, active = {
			reload: function () {
				var tableReload = $('#tableReload');
				//执行重载
				table.reloadData('tableReload', {
					page: {
						curr: 1 //重新从第 1 页开始
					}
					, where: {
						username: tableReload.val()
					}
				}, 'data');
			}
		};

		$('#search').on('click', function () {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});

		$(".data-clear-btn").on("click", function () {
			layer.confirm('清除所有数据库操作日志？', function (index) {
					$.post('<{CAUrl("log","clear")}>',function (res) {
						if (res.status == 1) {
							layer.msg(res.info, { icon: 1, time: 1000 }, function () {
								table.reloadData('tableReload');
								layer.close(index);
							});
						} else {
							layer.msg(res.info, { icon: 2, anim: 6, time: 5000 });
						}
					});
				});
			return false;
		});
	});
</script>